package com.xjy.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjy.common.annotation.DataScope;
import com.xjy.common.core.mybatisplus.core.ServicePlusImpl;
import com.xjy.common.core.page.PagePlus;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.utils.PageUtils;
import com.xjy.common.utils.SecurityUtils;
import com.xjy.system.domain.SysBudgetStatistics;
import com.xjy.system.domain.bo.SysBudgetStatisticsQueryBo;
import com.xjy.system.domain.vo.SysBudgetStatisticsVo;
import com.xjy.system.domain.vo.SysContractResultVo;
import com.xjy.system.mapper.SysBudgetStatisticsMapper;
import com.xjy.system.service.ISysBudgetStatisticsService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 预算管理之预算汇总Service业务层处理
 *
 * @author mlb
 * @date 2022-03-10
 */
@Service
public class SysBudgetStatisticsServiceImpl extends ServicePlusImpl<SysBudgetStatisticsMapper, SysBudgetStatistics> implements ISysBudgetStatisticsService {

    @Override
    public SysBudgetStatisticsVo queryById(String subjectName){
        return getVoById(subjectName, SysBudgetStatisticsVo.class);
    }

    @Override
    public TableDataInfo<SysBudgetStatisticsVo> queryPageList(SysBudgetStatisticsQueryBo bo) {

		List<SysBudgetStatisticsVo> list = null;
		Long id = SecurityUtils.getLoginUser().getUser().getUserId();
		if (SecurityUtils.isAdmin(id)) {
			list = baseMapper.queryPageList(bo,null);
		} else {
			list = baseMapper.queryPageList(bo,SecurityUtils.getLoginUser().getUser().getDeptId());
		}
		return PageUtils.buildDataInfo(list);
    }

    @Override
    public List<SysBudgetStatisticsVo> queryList(SysBudgetStatisticsQueryBo bo) {
        return listVo(buildQueryWrapper(bo), SysBudgetStatisticsVo.class);
    }

    private LambdaQueryWrapper<SysBudgetStatistics> buildQueryWrapper(SysBudgetStatisticsQueryBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<SysBudgetStatistics> lqw = Wrappers.lambdaQuery();
        lqw.like(StrUtil.isNotBlank(bo.getSubjectName()), SysBudgetStatistics::getSubjectName, bo.getSubjectName());
        lqw.like(StrUtil.isNotBlank(bo.getProjName()), SysBudgetStatistics::getProjName, bo.getProjName());
		lqw.eq(StrUtil.isNotBlank(bo.getBudgetId()), SysBudgetStatistics::getBudgetId, bo.getBudgetId());
		lqw.eq(StrUtil.isNotBlank(bo.getLevel()), SysBudgetStatistics::getLevel, bo.getLevel());
		lqw.eq(SysBudgetStatistics::getProjId, bo.getProjId());  //没有参数按null来查询
		lqw.eq(StrUtil.isNotBlank(bo.getAttribute()), SysBudgetStatistics::getAttribute, bo.getAttribute());
        return lqw;
    }
}
